﻿@using WebVella.Erp.Web.Models;
@using WebVella.TagHelpers.Models;
@{
	var record = (EntityRecord)Model;
	var rows = (List<dynamic>)record["data"];
	var hasHeader = (bool)record["hasHeader"];
	var hasHeaderColumn = (bool)record["hasHeaderColumn"];
	var lang = (string)record["lang"];
	var columns = new List<WvGridColumnMeta>();
	if (rows.Count > 0)
	{
		var sample = (IDictionary<string, object>)rows[0];
		var index = 1;
		foreach (var prop in sample.Keys)
		{
			columns.Add(new WvGridColumnMeta()
			{
				Label = hasHeader ? prop : "Field" + index,
				Name = "Field" + index
			});
			index++;
		}
	}
	var noRecordsMessage = "No records found in data";
	if (lang == "bg")
	{
		noRecordsMessage = "Няма открити записи";
	}
}

@if (rows.Count > 0)
{
	<wv-grid small="true" bordered="true" hover="true" has-tfoot="false" has-thead="hasHeader" columns="columns">
		@foreach (IDictionary<string, object> row in rows)
		{
			var firstColumn = true;
			<wv-grid-row>
				@foreach (var column in columns)
				{
					var isHeader = false;
					if (firstColumn && hasHeaderColumn)
					{
						isHeader = true;
						firstColumn = false;
					}
					<wv-grid-column is-header="@isHeader">
						@(row[column.Label])
					</wv-grid-column>

				}
			</wv-grid-row>
		}
	</wv-grid>
}
else
{
	<div class="alert alert-info p-2">@noRecordsMessage</div>
}
